<%-- 
    Document   : db1
    Created on : 2014/8/19, 下午 01:28:56
    Author     : gjun
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String id= request.getParameter("id");//抓取id值
    //import時 注意要java.sql.的開頭
    Class.forName("com.mysql.jdbc.Driver");//載入資料庫驅動程式
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb","root","root") ;
          //  .getConnection(Services頁-內的database的connection內的URL,帳號,密碼)
    Statement st= con.createStatement();
    String sql="select id,username,tel,birthday from person where id=" + id ;//select id值
          //把sql的新增語法從Navicat 的新增查詢 測試過OK的加入
    //String sql="select id , username , tel ,birthday from person where id=" + id ;
    System.out.println(sql);//輸出conlose 比對格式是否錯誤
    
       
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>修改內容 選擇</h1>
        <% 
            ResultSet rs= st.executeQuery(sql);
            if(rs.next()){//next有下一筆為ture
                //String id=rs.getString("id"); 重複了
                String username=rs.getString("username");
                String tel=rs.getString("tel");
                String birthday=rs.getString("birthday");
                //out.println(id+","+username+","+tel+","+birthday+"<br>");
        %>
                <form action="update2.jsp">
                    username:<input type="text" name="username" value="<%= username %>" ><br>
                    tel:<input type="text" name="tel"  value="<%= tel %>"><br>
                    birthday:<input type="text" name="birthday"  value="<%= birthday %>"><br>
                    <input type="hidden" name="id" value="<%= id%>">
                    <input type="submit" >
                </form>
                
        <%
                }else{
               out.println("找不到資料");  
            }
            rs.close();
            st.close();
            con.close();
        %>
    </body>
</html>
